//
//  InvestPrepareVC.swift
//  HengYouCai
//
//  Created by lwj on 2017/12/7.
//  Copyright © 2017年 lwj. All rights reserved.
//

import UIKit
import ReactiveCocoa
import Result
import ReactiveSwift


///实名认证
class InvestPrepareVC: BaseViewController {

    
    ///s银行列表
    var bankListArray:[BankModel] = []
    
    ///手机号
    var mobile:String?
    ///标题
    var titleName:String?
    ///协议
    var serviceAgreementLabel:String?
    ///支付开通说明 按钮
    var serviceButton:UIButton?
    
    
    
    /// 判断当前在哪一步
    var currentType = 0
    
    /// 上放的进度view
    var topBgView : UIView?
    
    /// 背景view
    var bgScrollView : UIScrollView?
    
    /// 银行信息
    var bankInfoView : BankView = BankView()
    
    /// 实名信息
    var realNameView = RealNameView()
    /// 实名信息
    var dealPswView = DealPswView()
    /// 银行id\
    var bankID = ""
    override func viewDidLoad() {
        super.viewDidLoad()

        
        leftBtnItem()

        bgScrollView = UIScrollView(frame: self.view.bounds)
        
        if JCWSCREENW > 320 {
             bgScrollView?.contentSize = CGSize(width: JCWSCREENW, height: self.view.bounds.size.height-kJcwGetNavHeight() + 1)
        }else{
            bgScrollView?.contentSize = CGSize(width: JCWSCREENW, height: self.view.bounds.size.height-kJcwGetNavHeight() + 100)
        }

        
        bgScrollView?.backgroundColor = Normal_458Color
        self.view.addSubview(bgScrollView!)
        
        let pswWord = UserDefaults.standard.string(forKey: kUserPaypassword) ?? ""
        let realname = UserDefaults.standard.string(forKey: kRealnameStatus) ?? ""
        
        // 没有设置交易密码 或者是 没有 实名认证跳三部曲
        if realname != "1"{
            self.navigationItem.title = "实名认证"
            currentType = 0
        }else if pswWord.count > 1 && realname == "1"{
            self.navigationItem.title = "风险测评"
            currentType = 2
        }else{
            self.navigationItem.title = "设置交易密码"
            currentType = 1

        }
        
        layoutHeatherViewWithType(currentType)
        
        switch currentType {
        case 0:
            layoutSubviewWithOneType(0)
        case 1:
            layoutSubviewWithTwoType()
        case 2:
            layoutSubviewWithThreeType()
        default:
            layoutSubviewWithOneType(0)
        }
        loadDate()
    }
    /// 数据请求
    func loadDate() {
        //
        self.view.showHUDLoading()
        HYCNetService.accountActionBankList(onSuccess: { (result) in
            
            self.view.hideHUDLoading(0)
            self.bankListArray = BankModel.mj_objectArray(withKeyValuesArray: result?["bankList"]) as! Array<BankModel>
            let json = JSON(result as Any)
            self.bankInfoView.phoneNumberTF.text = json["mobile"].stringValue
            self.serviceAgreementLabel = json["serviceAgreementLabel"].stringValue
            self.serviceButton?.setTitle(String(format: "《%@》", json["serviceAgreementLabel"].stringValue), for: .normal)
//            self.nextBtn.setTitle(json["buttonLabel"].stringValue, for: .normal)
        }) { (code, errorMsg) in
            //
            self.view.showHUDFailTips(errorMsg, hideDelay: kHUDHideDelay)
        }
    }
    /// 自定义返回按钮
    func leftBtnItem() {
        let backBtn = UIButton(type: .custom)
        backBtn.setImage(UIImage(named: "back"), for: .normal)
        backBtn.frame = CGRect(x: 0, y: 0, width: 100, height: 40)
//        backBtn.setim
        backBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0)
        backBtn.contentHorizontalAlignment = .left
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: backBtn)
        
        weak var weakSelf = self
        
        backBtn.reactive.controlEvents(.touchUpInside).observeValues { (result) in
            
            weakSelf?.view.endEditing(true)
            if self.currentType == 0 {
                JCWCommonAlertView(title: "温馨提示", message: "退出实名认证后无法进行投资理财，确认退出吗？", btnLeftTitle: "确认退出", btnRightTitle: "继续认证", clickBack: { (tag, title) in
                    if tag == -1{
                        self.navigationController?.popViewController(animated: true)
                    }
                })
            }else if self.currentType == 1 {
                JCWCommonAlertView(title: "温馨提示", message: "设置交易密码可保障您的账号资金安全，确认退出吗？", btnLeftTitle: "确认退出", btnRightTitle: "继续设置", clickBack: { (tag, title) in
                    if tag == -1{
                        self.navigationController?.popViewController(animated: true)
                    }
                })
            }else{
                self.navigationController?.popViewController(animated: true)

            }
        }
    }
    ///一键默认
    fileprivate func oneKeyDefault(){
        HYCNetService.getUpdateUserDefaultLevel(onSuccess: { (result) in
            guard let dic = result else {
                self.view.hideHUDLoading(0)
                return
            }
            let json = JSON(dic)
            
            UserDefaults.standard.set(json["max_type"].intValue, forKey: kUserLevel)
            
            self.view.showHUDSuccessTips("测评成功", hideDelay: kHUDHideDelay)
            self.perform(#selector(self.popTheVC), with: nil, afterDelay: kHUDHideDelay)
        }) { (code, errMsg) in
            self.view.showHUDFailTips(errMsg, hideDelay: kHUDHideDelay)
        }
    }
    
    /// 风险测评
     func layoutSubviewWithThreeType() {
        weak var weakSelf = self

        
        
        for  subView in (bgScrollView?.subviews)! {
            if subView.tag != 10001 {
                subView.removeFromSuperview()
            }
        }
      
        var rect = CGRect(x: 15, y: 110, width: JCWSCREENW-30, height: self.view.bounds.height-kJcwGetNavHeight()-100-20)
        let currentLeave = UserDefaults.standard.integer(forKey: kUserLevel)
        if  currentLeave != 0 {
            
            if JCWSCREENW < 330 {
               rect = CGRect(x: 15, y: 110, width: JCWSCREENW-30, height: self.view.bounds.height - kJcwGetNavHeight()-100-20 + 100)
            }
            /// 已经进行过风险测评
            let riskView = JCWRiskAssessmentResultView(rect, JCWRiskAssessmentResultType(rawValue: currentLeave), .small) { (tag, btnTitle) in
                //
                if tag == -2 {
                    weakSelf?.oneKeyDefault()
                }else{
                    
                 
                    weakSelf?.navigationController?.popViewController(animated: true)
                }
                
            }

            self.view.showHUDLoading()
            HYCNetService.estimateLevel(withDict: ["levelType":currentLeave], onSuccess: { (result) in
                weakSelf?.view.hideHUDLoading(0)
                guard let dic = result else {return}
                let json = JSON(dic)
                //更新结果视图
                weakSelf?.bgScrollView?.addSubview(riskView)

                riskView.updateContentTV(json["tipsOne"].stringValue, json["tipsTwo"].stringValue,JCWRiskAssessmentResultType(rawValue: currentLeave))
                
            }) { (code, errMsg) in
                weakSelf?.view.showHUDFailTips(errMsg ?? "", hideDelay: kHUDHideDelay)
                
            }
            
        }else{
            /// 未进行过风险测评
            let riskView = JCWRiskAssessmentResultView(rect, .wsz, .smallNoImage) { (tag, btnTitle) in
                //
                if tag == -2 {
                    weakSelf?.oneKeyDefault()
                }else{
                    
                    let riskVC = RiskAppraiseViewC()
                    
                    weakSelf?.navigationController?.pushViewController(riskVC, animated: true)
                }
                
            }
            
            bgScrollView?.addSubview(riskView)
            riskView.updateContentTV("<font color='#666666'>根据监管部门规定，您在投资前必须完成风险测评。默认类型为</font><big><b><font color='#333333'> 进取型</font></b></big><font color='#666666'>，对投资金额</font><font color='#f5b9cf8'>无限制</font>", .wsz)
        }
        

    }
    /// 设置交易密码
    func layoutSubviewWithTwoType() {
        for  subView in (bgScrollView?.subviews)! {
            if subView.tag != 10001 {
                subView.removeFromSuperview()
            }
        }
        // 交易密码
        bgScrollView?.addSubview(dealPswView)
        _ = dealPswView.sd_layout()
            .topSpaceToView(topBgView,0)?
            .leftSpaceToView(bgScrollView,0)?
            .rightSpaceToView(bgScrollView,0)?
            .heightIs(realNameView.thisHeight)
        // 下一步
        
        bgScrollView?.addSubview(pswNextBtn)
        _ = pswNextBtn.sd_layout()
            .topSpaceToView(dealPswView,34)?
            .leftSpaceToView(bgScrollView,15)?
            .rightSpaceToView(bgScrollView,15)?
            .heightIs(45)
        
        pswNextBtn.addTarget(self, action: #selector(nextStep), for: .touchUpInside)
        
        dealPswCombineSingle()
    }
    
    /// 实名认证
   
    func layoutSubviewWithOneType(_ currentType: NSInteger) {
        
        

        // 姓名
        bgScrollView?.addSubview(realNameView)
        _ = realNameView.sd_layout()
            .topSpaceToView(topBgView,0)?
            .leftSpaceToView(bgScrollView,0)?
            .rightSpaceToView(bgScrollView,0)?
            .heightIs(realNameView.thisHeight)
        // 银行
        bgScrollView?.addSubview(bankInfoView)
        _ = bankInfoView.sd_layout()
            .topSpaceToView(realNameView,0)?
            .leftSpaceToView(bgScrollView,0)?
            .rightSpaceToView(bgScrollView,0)?
            .heightIs(bankInfoView.thisHeight)
        
        bgScrollView?.addSubview(nextBtn)
        _ = nextBtn.sd_layout()
            .topSpaceToView(bankInfoView,34)?
            .leftSpaceToView(bgScrollView,15)?
            .rightSpaceToView(bgScrollView,15)?
            .heightIs(45)
        realNameCombineSingle()
        realNameView.nameTF.sendActions(for: .editingChanged)
        realNameView.idCardTF.sendActions(for: .editingChanged)
        
        bankInfoView.bankBtn.reactive.controlEvents(.touchUpInside).observeValues { (btn) in
            /// 选择银行
            weak var weakSelf = self
            if let listArray = weakSelf?.bankListArray {
                let bankList = BankListVC()
                bankList.bankLists = listArray
                bankList.callBack = {(model) in
                    weakSelf?.bankInfoView.bankNameTF.text = model.bankName
                    weakSelf?.bankID = model.bankId
                }
                self.navigationController?.pushViewController(bankList, animated: true)
            }
           
            
        }
//        bankInfoView.getVerifiedCodeBtn.addTarget(self, action: #selector(getVerifiedCode(_:)), for: .touchUpInside)
        // 同意
       
        bgScrollView?.addSubview(agreeBtn)
        _ = agreeBtn.sd_layout()
            .topSpaceToView(nextBtn,7.5)?
            .leftSpaceToView(bgScrollView,15)?
            .autoWidthRatio(1)?
            .autoHeightRatio(1)

        
        let agreeLab = UILabel()
        agreeLab.text = "我阅读并已同意"
        agreeLab.textAlignment = .left
        agreeLab.textColor = Normal_999Color
        agreeLab.font = Font_WL(13)
        bgScrollView?.addSubview(agreeLab)
        _ = agreeLab.sd_layout()
            .centerYEqualToView(agreeBtn)?
            .leftSpaceToView(agreeBtn,7.5)?
            .autoHeightRatio(0)?
            .autoWidthRatio(1)
        agreeLab.setSingleLineAutoResizeWithMaxWidth(JCWSCREENW)
        serviceButton = UIButton(type: UIButtonType.custom)
//        paymentBtn.setTitle("《支付开通说明》", for: .normal)
        serviceButton!.setTitleColor(Normal_ThemeColor, for: .normal)
        serviceButton!.titleLabel?.font = Font_WL(13)
        bgScrollView?.addSubview(serviceButton!)
        _ = serviceButton!.sd_layout()
            .centerYEqualToView(agreeBtn)?
            .leftSpaceToView(agreeLab,0)?.heightIs(14)?.widthIs(115)
        
        serviceButton!.rac_signal(for: UIControlEvents.touchUpInside).subscribeNext { (_) in
            self.navigationController?.pushViewController(BannerWebViewVC(urlStr: JCW_Payment, title: self.serviceAgreementLabel), animated: true)
        }
        
    }
    func layoutHeatherViewWithType(_ currentType: NSInteger) {
        
        topBgView = UIView()
        topBgView?.tag = 10001
        topBgView?.backgroundColor = UIColor.white
        bgScrollView?.addSubview(topBgView!)
        _ = topBgView?.sd_layout()
            .topSpaceToView(bgScrollView,0)?
            .leftSpaceToView(bgScrollView,0)?
            .rightSpaceToView(bgScrollView,0)?
            .heightIs(100)
        
       
        topBgView?.addSubview(setPswLab)
        _ = setPswLab.sd_layout()
            .centerXEqualToView(topBgView)?
            .bottomSpaceToView(topBgView,25)?
            .autoWidthRatio(1)?
            .autoHeightRatio(0)
        setPswLab.setSingleLineAutoResizeWithMaxWidth(JCWSCREENW/3.0)
        
        
        topBgView?.addSubview(setPswImg)
        _ = setPswImg.sd_layout()
            .centerXEqualToView(setPswLab)?
            .bottomSpaceToView(setPswLab,25/2.0)?
            .heightIs(25)?
            .widthIs(25)
        let twoLab = UILabel()
        twoLab.textAlignment = .center
        twoLab.text = "2"
        twoLab.textColor = UIColor.white
        twoLab.font = Font_WL(10)
        twoLab.bounds = CGRect(x: 0, y: 0, width: 15, height: 15)
        twoLab.center = setPswImg.center
        twoLab.backgroundColor = UIColor.clear
        setPswImg.addSubview(twoLab)
        
        topBgView?.addSubview(realNameLab)
        _ = realNameLab.sd_layout()
            .bottomEqualToView(setPswLab)?
            .leftSpaceToView(topBgView,15)?
            .autoHeightRatio(0)?
            .autoWidthRatio(1)
        realNameLab.setSingleLineAutoResizeWithMaxWidth(JCWSCREENW/3.0)
        
        topBgView?.addSubview(realNameImg)
        _ = realNameImg.sd_layout()
            .centerXEqualToView(realNameLab)?
            .bottomEqualToView(setPswImg)?
            .heightIs(25)?
            .widthIs(25)
        let oneLab = UILabel()
        oneLab.textAlignment = .center
        oneLab.text = "1"
        oneLab.textColor = UIColor.white
        oneLab.font = Font_WL(10)
        oneLab.bounds = CGRect(x: 0, y: 0, width: 15, height: 15)
        oneLab.center = realNameImg.center
        oneLab.backgroundColor = UIColor.clear
        realNameImg.addSubview(oneLab)
        
        
        topBgView?.addSubview(riskLab)
        _ = riskLab.sd_layout()
            .bottomEqualToView(setPswLab)?
            .rightSpaceToView(topBgView,15)?
            .autoHeightRatio(0)?
            .autoWidthRatio(1)
        riskLab.setSingleLineAutoResizeWithMaxWidth(JCWSCREENW/3.0)
       
        topBgView?.addSubview(riskImg)
        _ = riskImg.sd_layout()
            .centerXEqualToView(riskLab)?
            .bottomEqualToView(setPswImg)?
            .heightIs(25)?
            .widthIs(25)
        let threeLab = UILabel()
        threeLab.textAlignment = .center
        threeLab.text = "3"
        threeLab.textColor = UIColor.white
        threeLab.font = Font_WL(10)
        threeLab.bounds = CGRect(x: 0, y: 0, width: 15, height: 15)
        threeLab.center = riskImg.center
        threeLab.backgroundColor = UIColor.clear
        riskImg.addSubview(threeLab)
        
        
        topBgView?.addSubview(line1)
        _ = line1.sd_layout()
            .centerYEqualToView(setPswImg)?
            .rightSpaceToView(setPswImg,-4)?
            .leftSpaceToView(realNameImg,0)?
            .heightIs(1)
        
        topBgView?.addSubview(line2)
        _ = line2.sd_layout()
            .centerYEqualToView(setPswImg)?
            .rightSpaceToView(riskImg,0)?
            .leftSpaceToView(setPswImg,-4)?
            .heightIs(1)
        
    }
    
    
    /// 倒计时
    func customTimer(_ btn : UIButton) {
      
        // 定义需要计时的时间
        var timeCount = 60
        // 在global线程里创建一个时间源
        let codeTimer = DispatchSource.makeTimerSource(queue:      DispatchQueue.global())
        // 设定这个时间源是每秒循环一次，立即开始
        codeTimer.scheduleRepeating(deadline: .now(), interval: .seconds(1))
        // 设定时间源的触发事件
        codeTimer.setEventHandler(handler: {
            // 每秒计时一次
            print(timeCount)
            // 时间到了取消时间源
            if timeCount <= 0 {
                DispatchQueue.main.async {
                    btn.isEnabled = true
                    btn.setTitle("获取验证码", for: .normal)
                }
                codeTimer.cancel()
                
            }else{
                // 返回主线程处理一些事件，更新UI等等
                DispatchQueue.main.async {
                    btn.setTitle(String(format: "(%d)s",timeCount), for: .normal)
                }
            }
            timeCount = timeCount - 1

            
        })
        // 启动时间源
        codeTimer.resume()

    }
    
    /// 实名认证界面聚合信号 监听按钮的颜色与enable
    func realNameCombineSingle() {
        //
        
        let nameSingle = realNameView.nameTF.reactive.continuousTextValues.map { (text) -> Bool in
            
            return text!.count > 0
        }
        let idCardSingle = realNameView.idCardTF.reactive.continuousTextValues.map { (text) -> Bool in
            
            return text!.count > 0
        }
       
        let bankCodeSingle = bankInfoView.bankCodeTF.reactive.continuousTextValues.map { (text) -> Bool in
            
            return text!.count > 0
        }
        
       
        let nextBtnSingle = Signal.combineLatest(nameSingle,idCardSingle,bankCodeSingle).map { (name,idCard,bankCode) in
            //
            return name && idCard && bankCode
        }
        nextBtnSingle.map { nextBtnSingle in
            let enable =  (nextBtnSingle && (self.bankInfoView.bankNameTF.text!.count > 0))
            self.nextBtn.isEnabled = enable
            return enable ? Normal_RedColor : Normal_BBBColor
            }.observeValues { (nextBtnColor) in
                self.nextBtn.backgroundColor = nextBtnColor
        }
        

    }
    /// 实名认证界面聚合信号 监听按钮的颜色与enable
    func dealPswCombineSingle() {
        let pswSingle = dealPswView.dealPswTF.reactive.continuousTextValues.map { (text) -> Bool in
            
            return text!.count > 0
        }
        let doulbePswSingle = dealPswView.doubleDealTF.reactive.continuousTextValues.map { (text) -> Bool in
            
            return text!.count > 0
        }
        let nextBtnSingle = Signal.combineLatest(pswSingle,doulbePswSingle).map { (psw,doublePsw) in
            //
            return psw && doublePsw
        }
        nextBtnSingle.map { nextBtnSingle in
            let enable =  nextBtnSingle
            self.pswNextBtn.isEnabled = enable
            return enable ? Normal_RedColor : Normal_BBBColor
            }.observeValues { (nextBtnColor) in
                self.pswNextBtn.backgroundColor = nextBtnColor
        }
    }
    func agreeOrDisagree(_ btn : UIButton) {
        //
        btn.isSelected = !btn.isSelected
    }
    /// 下一步
    func nextStep() {
        
       // 退出键盘
        self.view.endEditing(true)
        
        if currentType == 0 {
            // 没有同意支付协议
            if self.agreeBtn.isSelected {
                
                self.view.showHUDWarnTips(String(format: "请阅读并同意《%@》", self.serviceAgreementLabel ?? ""), hideDelay: kHUDHideDelay)
                return;
            }
            self.view.showHUDLoading()
            let paramDic = ["userName":realNameView.nameTF.text!,
                            "idCard":realNameView.idCardTF.text!,
                            "bankId":bankID,
                            "bankCode":bankInfoView.bankCodeTF.text!,
                            "mobile":bankInfoView.phoneNumberTF.text!,
                            ]
            // 提交实名认证请求
            weak var weakSelf = self
            HYCNetService.realNameReadyBind(withDict: paramDic, onSuccess: { (result) in
                weakSelf?.view.hideHUDLoading(0)
                
                guard let length = result?["smsCodeMaxLen"] as? String, length.cGInt > 0 else {return}
                JCWBFInputSMSCodeAlertView(phoneNumber: weakSelf?.bankInfoView.phoneNumberTF.text, num: length.cGInt, sureHandler: { (messageCode) in
                    //
                    weakSelf?.view.showHUDLoading()

                    HYCNetService.realNamecConfirmBind(withDict: ["smsCode":messageCode], onSuccess: { (result2) in
                    
                        weakSelf?.view.hideHUDLoading(0)
                        
                        // 成功之后保存数据做跳转
                        UserDefaults.standard.set(result2?["realNameStatus"], forKey: kRealnameStatus)
                        UserDefaults.standard.set(result2?["realName"], forKey: kUserRealname)
                        UserDefaults.standard.set(result2?["idCard"], forKey: kUserIdCard)
                        UserDefaults.standard.set(result2?["cardStatus"], forKey: kCardStatus)
                        
                      
                        weakSelf?.realNameSuccess()
                        
                    }, andFailed: { (code, errorMsg) in
                        
                        weakSelf?.view.showHUDWarnTips(errorMsg, hideDelay: kHUDHideDelay)
                    })
                })
            }) { (code, errorMsg) in
                weakSelf?.view.showHUDWarnTips(errorMsg, hideDelay: kHUDHideDelay)

            }

            
        }else{
            
            if dealPswView.dealPswTF.text != dealPswView.doubleDealTF.text {
                self.view.makeToast("两次输入密码不一致，请重新输入", duration: 1, position: CSToastPositionCenter)

                return
            }
            if dealPswView.dealPswTF.text!.count < 6 || dealPswView.doubleDealTF.text!.count < 6 {
                self.view.makeToast("交易密码必须为六位", duration: 1, position: CSToastPositionCenter)
                
                return
            }
            self.view.showHUDLoading()
            
            HYCNetService.accountSetTradePassword(withDict: ["tradePassword":dealPswView.dealPswTF.text!], onSuccess: { (result) in
                //
                self.view.hideHUDLoading(0)
                UserDefaults.standard.set(self.dealPswView.dealPswTF.text!, forKey: kUserPaypassword)
                
                self.currentType = self.currentType + 1

                self.setDealPswSuccess()
                
            }, andFailed: { (code, errorMsg) in
                self.view.makeToast(errorMsg, duration: 1, position: CSToastPositionCenter)

            })
            
        }

    }
    
    /// 实名认证成功
    func realNameSuccess() {
        self.navigationItem.title = "设置交易密码"
        
        let pswWord = UserDefaults.standard.string(forKey: kUserPaypassword)
        if pswWord!.count > 0 {
            self.currentType = 2

        }else{
            self.currentType = self.currentType + 1

        }
        doAnimation()
        
        /// 如设置过交易密码 直接跳测评界面
        if currentType == 2 {
            
            self.perform(#selector(layoutSubviewWithThreeType), with: nil, afterDelay: 1)
            
            setPswImg.image = UIImage(named: "Identf_circular01")
            line1.backgroundColor =  Normal_ThemeColor//Normal_RedColor
            line2.backgroundColor =  Normal_ThemeColor//Normal_RedColor
            riskImg.image = UIImage(named: "Identf_circular01")
            riskLab.textColor = Normal_333Color
            setPswLab.textColor = Normal_333Color
            circle2.backgroundColor = UIColor.clear
            circle1.backgroundColor = UIColor.clear
            redLine1.backgroundColor = UIColor.clear
            redLine2.backgroundColor = UIColor.clear
            return
        }
        self.perform(#selector(layoutSubviewWithTwoType), with: nil, afterDelay: 1)
        
        setPswImg.image = UIImage(named: "Identf_circular01")
        setPswLab.textColor = Normal_333Color
        line1.backgroundColor =  Normal_ThemeColor   //Normal_RedColor
        circle1.backgroundColor = UIColor.clear
        redLine1.backgroundColor = UIColor.clear
        circle2.backgroundColor = Normal_ThemeColor//Normal_RedColor
        redLine2.backgroundColor = Normal_ThemeColor //Normal_RedColor
    }
    
    /// 设置交易密码成功
    func setDealPswSuccess() {
        self.navigationItem.title = "风险测评"
        doAnimation()
        
        self.perform(#selector(layoutSubviewWithThreeType), with: nil, afterDelay: 1)
        
        line1.backgroundColor = Normal_RedColor
        line2.backgroundColor = Normal_RedColor
        riskImg.image = UIImage(named: "Identf_circular01")
        riskLab.textColor = Normal_333Color
        circle2.backgroundColor = UIColor.clear
        redLine2.backgroundColor = UIColor.clear
    }
    
    /// 做跳转动画
    func doAnimation()  {
        let animation = CATransition()
        animation.type = "rippleEffect"
        animation.duration = 1
        bgScrollView?.layer.add(animation, forKey: "animation")
    }
    // 设置交易密码
    lazy var setPswLab: UILabel = {
        let setPswLab = UILabel()
        setPswLab.text = "设置交易密码"
        setPswLab.textColor = (self.currentType > 0) ? Normal_333Color : Normal_999Color
        setPswLab.font = Font_WL(13)
        setPswLab.textAlignment = .center
        return setPswLab
    }()
    // 设置交易密码图片
    lazy var setPswImg: UIImageView = {
    
        let imgName = (self.currentType > 0) ? "Identf_circular01" : "Identf_circular02"
        let setPswImg = UIImageView(image: UIImage(named: imgName))
        
        return setPswImg
    }()
    // 实名认证
    lazy var realNameLab: UILabel = {
        let realNameLab = UILabel()
        realNameLab.text = "实名认证"
        realNameLab.textColor =  Normal_333Color
        realNameLab.font = Font_WL(13)
        realNameLab.textAlignment = .center
        return realNameLab
    }()
    // 实名认证图片
    lazy var realNameImg: UIImageView = {
        let realNameImg = UIImageView(image: UIImage(named: "Identf_circular01"))
        return realNameImg
    }()
    lazy var riskLab: UILabel = {
        let riskLab = UILabel()
        riskLab.text = "风险测评"
        riskLab.textColor = (self.currentType > 1) ? Normal_333Color : Normal_999Color
        riskLab.font = Font_WL(13)
        riskLab.textAlignment = .center
        return riskLab
    }()
    lazy var riskImg: UIImageView = {
        let imgName = (self.currentType > 1) ? "Identf_circular01" : "Identf_circular02"

        let riskImg = UIImageView(image: UIImage(named: imgName))

        return riskImg
    }()
    lazy var line1: UIView = {
        let line1 = UIView()
        line1.backgroundColor = (self.currentType > 0) ? Normal_RedColor : Normal_BBBColor
        line1.addSubview(self.circle1)
        _ = self.circle1.sd_layout().centerXEqualToView(line1)?.centerYEqualToView(line1)?.heightIs(4.5)?.widthIs(4.5)
        line1.addSubview(self.redLine1)
        _ = self.redLine1.sd_layout().topSpaceToView(line1,0)?.leftSpaceToView(line1,0)?.bottomSpaceToView(line1,0)?.rightEqualToView(self.circle1)
        return line1
    }()
    lazy var redLine1: UIView = {
        let temp = UIView()
        temp.backgroundColor = (self.currentType == 0) ? Normal_ThemeColor : UIColor.clear//Normal_RedColor
        return temp
    }()
    lazy var circle1: UIView = {
        let temp = UIView()
        temp.backgroundColor = (self.currentType == 0) ? Normal_ThemeColor: UIColor.clear//Normal_RedColor
        temp.layer.cornerRadius = 4.5/2
        temp.clipsToBounds = true
        temp.bounds = CGRect(x: 0, y: 0, width: 4.5, height: 4.5)
        return temp
    }()
    lazy var line2: UIView = {
        let line2 = UIView()

        line2.backgroundColor = (self.currentType == 2) ? Normal_ThemeColor : Normal_BBBColor//Normal_RedColor
        line2.addSubview(self.circle2)
        _ = self.circle2.sd_layout().centerXEqualToView(line2)?.centerYEqualToView(line2)?.heightIs(4.5)?.widthIs(4.5)
        line2.addSubview(self.redLine2)
        _ = self.redLine2.sd_layout().topSpaceToView(line2,0)?.leftSpaceToView(line2,0)?.bottomSpaceToView(line2,0)?.rightEqualToView(self.circle2)
        return line2
    }()
    lazy var redLine2: UIView = {
        let temp = UIView()
        temp.backgroundColor = (self.currentType == 1) ? Normal_ThemeColor : UIColor.clear //Normal_RedColor
        
        return temp
    }()
    lazy var circle2: UIView = {
        let temp = UIView()
        temp.backgroundColor = (self.currentType == 1) ? Normal_RedColor : UIColor.clear
        temp.layer.cornerRadius = 4.5/2
        temp.clipsToBounds = true
        temp.bounds = CGRect(x: 0, y: 0, width: 4.5, height: 4.5)
        return temp
    }()
    lazy var agreeBtn: UIButton = {
        let temp = UIButton(type: UIButtonType.custom)
        temp.setImage(UIImage(named: "recharge_invest_agre"), for: .normal)
        temp.setImage(UIImage(named: "recharge_invest_agre01"), for: .selected)
        temp.addTarget(self, action: #selector(agreeOrDisagree), for: .touchUpInside)

        return temp
    }()
    lazy var nextBtn: UIButton = {
        //         下一步
        let temp = UIButton(type: UIButtonType.custom)
        temp.setTitle("下一步", for: .normal)
        temp.layer.cornerRadius = 5
        temp.setTitleColor(UIColor.white, for: .normal)
        temp.titleLabel?.font = Font_WL(14)
        temp.backgroundColor = Normal_BBBColor
        temp.isEnabled = false
        
        temp.addTarget(self, action: #selector(nextStep), for: .touchUpInside)
        
        return temp
    }()
    lazy var pswNextBtn: UIButton = {
        let nextBtn = UIButton(type: UIButtonType.custom)
        nextBtn.setTitle("下一步", for: .normal)
        nextBtn.layer.cornerRadius = 5
        nextBtn.setTitleColor(UIColor.white, for: .normal)
        nextBtn.titleLabel?.font = Font_WL(14)
        nextBtn.backgroundColor = Normal_BBBColor
        nextBtn.isEnabled = false

        return nextBtn
    }()
}

/// 实名认证信息
class RealNameView: UIView {
    
    var thisHeight : CGFloat = 0
    /// 标题lab的宽度
    var titleLabWith : CGFloat = 0
    /// 输入框到标题lab的距离
    var tfTotitleLabWith : CGFloat = 4
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = Normal_458Color
        
        initUI()
        
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func initUI() {
        
        
        /// 提示文字
        let titleLab = UILabel(frame: CGRect( x: 15, y: 7.5, width: JCWSCREENW-30, height: 0))
        titleLab.textColor = Normal_999Color
        titleLab.textAlignment = .left
        titleLab.font = Font_WL(12)
        titleLab.text = "请确认本人真实姓名及身份信息，认证通过，无法更改"
        titleLab.numberOfLines = 0
        titleLab.sizeToFit()

        self.addSubview(titleLab)
        
        /// 有圆角的背景
        let bgView = UIView()
        bgView.backgroundColor = UIColor.white
        bgView.layer.cornerRadius = 10
        bgView.clipsToBounds = true
        self.addSubview(bgView)
        _ = bgView.sd_layout()
            .leftEqualToView(titleLab)?
            .topSpaceToView(titleLab,15/2.0)?
            .rightSpaceToView(self,15)?
            .heightIs(90)
        
        /// 记录当期view的高度
        thisHeight = titleLab.height + bgView.height + 15
        debugPrint(thisHeight)
        /// 灰线
        let lineView = UIView()
        lineView.backgroundColor = Normal_CCCColor
        bgView.addSubview(lineView)
        _ = lineView.sd_layout()
            .centerYEqualToView(bgView)?
            .leftSpaceToView(bgView,12.5)?
            .rightSpaceToView(bgView,12.5)?
            .heightIs(0.5)
        /// 名字
        let nameLab = UILabel()
        nameLab.text = "姓名"
        nameLab.textAlignment = .left
        nameLab.textColor = Normal_333Color
        nameLab.font = Font_WL(14)
        bgView.addSubview(nameLab)
        _ = nameLab.sd_layout()
            .topSpaceToView(bgView,0)?
            .leftSpaceToView(bgView,44)?
            .bottomSpaceToView(lineView,0)?
            .widthIs(titleLabWith)
        
        /// 名字图片
        let nameImg = UIImageView(image: UIImage(named: "Identf_name"))
        bgView.addSubview(nameImg)
        _ = nameImg.sd_layout()
            .centerYEqualToView(nameLab)?
            .rightSpaceToView(nameLab,12)?
            .heightIs(20)?
            .widthIs(20)
        
        /// 名字输入框
        bgView.addSubview(nameTF)
        _ = nameTF.sd_layout()
            .leftSpaceToView(nameLab,tfTotitleLabWith)?
            .topSpaceToView(bgView,0)?
            .bottomSpaceToView(lineView,0)?
            .rightEqualToView(lineView)
        /// 身份证
        let idCardLab = UILabel()
        idCardLab.text = "身份证"
        idCardLab.textAlignment = .left
        idCardLab.textColor = Normal_333Color
        idCardLab.font = Font_WL(14)
        bgView.addSubview(idCardLab)
        _ = idCardLab.sd_layout()
            .topSpaceToView(lineView,0)?
            .leftSpaceToView(bgView,44)?
            .bottomSpaceToView(bgView,0)?
            .widthIs(titleLabWith)
        /// 身份证图片
        let idCardImg = UIImageView(image: UIImage(named: "Identf_IDcard"))
        bgView.addSubview(idCardImg)
        _ = idCardImg.sd_layout()
            .centerYEqualToView(idCardLab)?
            .rightSpaceToView(idCardLab,12)?
            .heightIs(20)?
            .widthIs(20)
        /// 身份证输入框
        bgView.addSubview(idCardTF)
        _ = idCardTF.sd_layout()
            .leftSpaceToView(idCardLab,tfTotitleLabWith)?
            .topSpaceToView(lineView,0)?
            .bottomSpaceToView(bgView,0)?
            .rightEqualToView(lineView)
    }
    
    lazy var nameTF: UITextField = {
        let temp = UITextField()
        let placeholderStr = NSAttributedString(string:"请输入真实姓名", attributes: [NSForegroundColorAttributeName : Normal_999Color.cgColor])
//        temp.placeholder = "请输入真实姓名"
        temp.attributedPlaceholder = placeholderStr
        temp.font = Font_WL(14)
        temp.textColor = Normal_333Color
        let realName = UserDefaults.standard.string(forKey: kUserRealname)
        //        if realName?.count > 0 {
        temp.text = realName
        return temp
    }()
    lazy var idCardTF: UITextField = {
        let temp = UITextField()
        let placeholderStr = NSAttributedString(string:"请输入真实身份证号", attributes: [NSForegroundColorAttributeName : Normal_999Color.cgColor])
        temp.attributedPlaceholder = placeholderStr
        temp.font = Font_WL(14)
        temp.textColor = Normal_333Color
        temp.clearButtonMode = .whileEditing
        let idCard = UserDefaults.standard.string(forKey: kUserIdCard)
        //        if realName?.count > 0 {
        temp.text = idCard

        return temp
    }()
}
/// 绑卡信息
class BankView: UIView {
    ///电话号码
    var mobile:String?
    
    
    var thisHeight : CGFloat = 0
    
    /// 标题lab的宽度
    var titleLabWith : CGFloat = 0
    /// 输入框到标题lab的距离
    var tfTotitleLabWith : CGFloat = 4
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = Normal_458Color
        initUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func initUI() {
        
        
        /// 提示文字
        let detailLab = UILabel(frame: CGRect( x: 15, y: 7.5, width: JCWSCREENW-30, height: 0))
        detailLab.textColor = Normal_999Color
        detailLab.textAlignment = .left
        detailLab.font = Font_WL(12)
        detailLab.text = "温馨提示：若银行卡为二类账户，将会影响提现，具体账户类型可咨询发卡行"
        detailLab.numberOfLines = 0
        detailLab.sizeToFit()
        
        self.addSubview(detailLab)
        
        /// 有圆角的背景
        let bgView = UIView()
        bgView.backgroundColor = UIColor.white
        bgView.layer.cornerRadius = 10
        bgView.clipsToBounds = true
        self.addSubview(bgView)
        _ = bgView.sd_layout()
            .leftEqualToView(detailLab)?
            .topSpaceToView(detailLab,15/2.0)?
            .rightSpaceToView(self,15)?
            .heightIs(45*3)
        
        /// 记录当期view的高度
        thisHeight = detailLab.height + bgView.height + 15
//        debugPrint(thisHeight)
        /// 灰线3
        let line2View = UIView()
        line2View.backgroundColor = Normal_CCCColor
        bgView.addSubview(line2View)
        _ = line2View.sd_layout()
            .topSpaceToView(bgView,90)?
            .leftSpaceToView(bgView,12.5)?
            .rightSpaceToView(bgView,12.5)?
            .heightIs(0.5)
        /// 灰线1
        let line1View = UIView()
        line1View.backgroundColor = Normal_CCCColor
        bgView.addSubview(line1View)
        _ = line1View.sd_layout()
            .bottomSpaceToView(line2View,45)?
            .leftEqualToView(line2View)?
            .rightEqualToView(line2View)?
            .heightIs(0.5)

        /// 开户银行
        let bankLab = UILabel()
        bankLab.text = "开户银行"
        bankLab.textAlignment = .left
        bankLab.textColor = Normal_333Color
        bankLab.font = Font_WL(14)
        bgView.addSubview(bankLab)
        _ = bankLab.sd_layout()
            .topSpaceToView(bgView,0)?
            .leftSpaceToView(bgView,44)?
            .bottomSpaceToView(line1View,0)?
            .widthIs(titleLabWith)
        
        /// 开户银行图片
        let bankImg = UIImageView(image: UIImage(named: "Identf_bank"))
        bgView.addSubview(bankImg)
        _ = bankImg.sd_layout()
            .centerYEqualToView(bankLab)?
            .rightSpaceToView(bankLab,12)?
            .heightIs(20)?
            .widthIs(20)
        
        /// 开户银行输入框
        bgView.addSubview(bankNameTF)
        _ = bankNameTF.sd_layout()
            .leftSpaceToView(bankLab,tfTotitleLabWith)?
            .topSpaceToView(bgView,0)?
            .bottomSpaceToView(line1View,0)?
            .rightEqualToView(line1View)?.offset(50)
        /// 开户银行right图片
        let rightImg = UIImageView(image: UIImage(named: "right"))
        bgView.addSubview(rightImg)
        _ = rightImg.sd_layout()
            .centerYEqualToView(bankLab)?
            .rightEqualToView(line1View)?
            .widthIs(7.5)?
            .heightIs(13)
        /// 选择开户银行按钮
        bgView.addSubview(bankBtn)
        _ = bankBtn.sd_layout()
            .topSpaceToView(bgView,0)?
            .leftEqualToView(bankImg)?
            .bottomEqualToView(bankLab)?
            .rightEqualToView(rightImg)
        /// 银行卡号
        let bankCodeLab = UILabel()
        bankCodeLab.text = "银行卡号"
        bankCodeLab.textAlignment = .left
        bankCodeLab.textColor = Normal_333Color
        bankCodeLab.font = Font_WL(14)
        bgView.addSubview(bankCodeLab)
        _ = bankCodeLab.sd_layout()
            .topSpaceToView(line1View,0)?
            .leftSpaceToView(bgView,44)?
            .bottomSpaceToView(line2View,0)?
            .widthIs(titleLabWith)
        /// 银行卡图片
        let bankCodeImg = UIImageView(image: UIImage(named: "Identf_bankcard"))
        bgView.addSubview(bankCodeImg)
        _ = bankCodeImg.sd_layout()
            .centerYEqualToView(bankCodeLab)?
            .rightSpaceToView(bankCodeLab,12)?
            .heightIs(20)?
            .widthIs(20)
        /// 银行卡号输入框
        bgView.addSubview(bankCodeTF)
        _ = bankCodeTF.sd_layout()
            .leftSpaceToView(bankCodeLab,tfTotitleLabWith)?
            .topSpaceToView(line1View,0)?
            .bottomSpaceToView(line2View,0)?
            .rightEqualToView(line2View)
        
        /// 预留手机
        let phoneLab = UILabel()
        phoneLab.text = "预留手机"
        phoneLab.textAlignment = .left
        phoneLab.textColor = Normal_333Color
        phoneLab.font = Font_WL(14)
        bgView.addSubview(phoneLab)
        _ = phoneLab.sd_layout()
            .topSpaceToView(line2View,0)?
            .leftSpaceToView(bgView,44)?
            .bottomSpaceToView(bgView,0)?
            .widthIs(titleLabWith)
        
        /// 预留手机图片
        let phoneImg = UIImageView(image: UIImage(named: "Identf_phone"))
        bgView.addSubview(phoneImg)
        _ = phoneImg.sd_layout()
            .centerYEqualToView(phoneLab)?
            .rightSpaceToView(phoneLab,12)?
            .heightIs(20)?
            .widthIs(20)
        
        /// 预留手机输入框
        bgView.addSubview(phoneNumberTF)
        _ = phoneNumberTF.sd_layout()
            .leftSpaceToView(phoneLab,tfTotitleLabWith)?
            .topSpaceToView(line2View,0)?
            .bottomSpaceToView(bgView,0)?
            .rightEqualToView(line2View)
        
    }
    
    
    lazy var bankNameTF: UITextField = {
        let temp = UITextField()
        let placeholderStr = NSAttributedString(string:"请选择开户银行", attributes: [NSForegroundColorAttributeName : Normal_999Color.cgColor])
        temp.isEnabled = false
        temp.attributedPlaceholder = placeholderStr
        temp.font = Font_WL(14)
        temp.textColor = Normal_333Color
        return temp
    }()
    lazy var bankCodeTF: UITextField = {
        let temp = UITextField()
        let placeholderStr = NSAttributedString(string:"请输入银行卡号", attributes: [NSForegroundColorAttributeName : Normal_999Color.cgColor])
        temp.attributedPlaceholder = placeholderStr
        temp.keyboardType = .numberPad
        temp.font = Font_WL(14)
        temp.textColor = Normal_333Color
        temp.clearButtonMode = .whileEditing

        return temp
    }()
    ///预留手机号
    lazy var phoneNumberTF: UITextField = {
        let temp = UITextField()
        let placeholderStr = NSAttributedString(string:"请输入银行预留手机号", attributes: [NSForegroundColorAttributeName : Normal_999Color.cgColor])
        //        temp.placeholder = "请输入真实姓名"
//        temp.text = UserDefaults.standard.object(forKey: kUserAccount) as? String
//        temp.text = "12345678901"
        temp.keyboardType = .numberPad
        temp.isEnabled = false
        temp.attributedPlaceholder = placeholderStr
        temp.font = Font_WL(14)
        temp.textColor = Normal_333Color
        return temp
    }()
    
    /// 点击选择银行卡按钮
    lazy var bankBtn: UIButton = {
        //
        let temp = UIButton(type: UIButtonType.custom)
        temp.backgroundColor = UIColor.clear
        return temp
    }()
    
}
/// 交易密码信息
class DealPswView: UIView ,UITextFieldDelegate{
    
    var thisHeight : CGFloat = 0
    /// 标题lab的宽度
    var titleLabWith : CGFloat = 0
    /// 输入框到标题lab的距离
    var tfTotitleLabWith : CGFloat = 4
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = Normal_458Color
        
        initUI()
        
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func initUI() {
        
        
        /// 提示文字
        let titleLab = UILabel(frame: CGRect( x: 15, y: 7.5, width: JCWSCREENW-30, height: 0))
        titleLab.textColor = Normal_999Color
        titleLab.textAlignment = .left
        titleLab.font = Font_WL(12)
        titleLab.text = "温馨提示：你在投资和提现过程中均需要使用该交易密码，请妥善保管密码，切勿告诉他人。"
        titleLab.numberOfLines = 0
        titleLab.sizeToFit()
        
        self.addSubview(titleLab)
        
        /// 有圆角的背景
        let bgView = UIView()
        bgView.backgroundColor = UIColor.white
        bgView.layer.cornerRadius = 10
        bgView.clipsToBounds = true
        self.addSubview(bgView)
        _ = bgView.sd_layout()
            .leftEqualToView(titleLab)?
            .topSpaceToView(titleLab,15/2.0)?
            .rightSpaceToView(self,15)?
            .heightIs(90)
        
        /// 记录当期view的高度
        thisHeight = titleLab.height + bgView.height + 15
        debugPrint(thisHeight)
        /// 灰线
        let lineView = UIView()
        lineView.backgroundColor = Normal_CCCColor
        bgView.addSubview(lineView)
        _ = lineView.sd_layout()
            .centerYEqualToView(bgView)?
            .leftSpaceToView(bgView,12.5)?
            .rightSpaceToView(bgView,12.5)?
            .heightIs(0.5)
        /// 交易密码
        let dealPswLab = UILabel()
        dealPswLab.text = "交易密码"
        dealPswLab.textAlignment = .left
        dealPswLab.textColor = Normal_333Color
        dealPswLab.font = Font_WL(14)
        bgView.addSubview(dealPswLab)
        _ = dealPswLab.sd_layout()
            .topSpaceToView(bgView,0)?
            .leftSpaceToView(bgView,44)?
            .bottomSpaceToView(lineView,0)?
            .widthIs(titleLabWith)
        
        /// 交易密码
        let dealPswImg = UIImageView(image: UIImage(named: "Identf_password"))
        bgView.addSubview(dealPswImg)
        _ = dealPswImg.sd_layout()
            .centerYEqualToView(dealPswLab)?
            .rightSpaceToView(dealPswLab,12)?
            .heightIs(20)?
            .widthIs(20)
        /// eye
        let eyeBtn = UIButton(type: UIButtonType.custom)
        eyeBtn.setImage(UIImage(named: "uneye"), for: .normal)
        eyeBtn.setImage(UIImage(named: "eye"), for: .selected)
        bgView.addSubview(eyeBtn)
        _ = eyeBtn.sd_layout()
            .centerYEqualToView(dealPswLab)?
            .rightEqualToView(lineView)?
            .heightIs(20)?
            .widthIs(20)
        eyeBtn.rac_signal(for: UIControlEvents.touchUpInside).subscribeNext { (_) in
            self.dealPswTF.isSecureTextEntry = eyeBtn.isSelected
            eyeBtn.isSelected = !eyeBtn.isSelected
        }
        /// 交易密码
        bgView.addSubview(dealPswTF)
        _ = dealPswTF.sd_layout()
            .leftSpaceToView(dealPswLab,tfTotitleLabWith)?
            .topSpaceToView(bgView,0)?
            .bottomSpaceToView(lineView,0)?
            .rightSpaceToView(eyeBtn,5)
        /// 交易密码再次确认
        let doubleDealLab = UILabel()
        doubleDealLab.text = "再次确认"
        doubleDealLab.textAlignment = .left
        doubleDealLab.textColor = Normal_333Color
        doubleDealLab.font = Font_WL(14)
        bgView.addSubview(doubleDealLab)
        _ = doubleDealLab.sd_layout()
            .topSpaceToView(lineView,0)?
            .leftSpaceToView(bgView,44)?
            .bottomSpaceToView(bgView,0)?
            .widthIs(titleLabWith)
        /// 身交易密码再次确认图片
        let doubleDealImg = UIImageView(image: UIImage(named: "Identf_con_password"))
        bgView.addSubview(doubleDealImg)
        _ = doubleDealImg.sd_layout()
            .centerYEqualToView(doubleDealLab)?
            .rightSpaceToView(doubleDealLab,12)?
            .heightIs(20)?
            .widthIs(20)
        
        /// eye
        let eyeBtn2 = UIButton(type: UIButtonType.custom)
        eyeBtn2.setImage(UIImage(named: "uneye"), for: .normal)
        eyeBtn2.setImage(UIImage(named: "eye"), for: .selected)
        bgView.addSubview(eyeBtn2)
        _ = eyeBtn2.sd_layout()
            .centerYEqualToView(doubleDealLab)?
            .rightEqualToView(lineView)?
            .heightIs(20)?
            .widthIs(20)
        eyeBtn2.rac_signal(for: UIControlEvents.touchUpInside).subscribeNext { (_) in
            self.doubleDealTF.isSecureTextEntry = eyeBtn2.isSelected
            eyeBtn2.isSelected = !eyeBtn2.isSelected
        }
        /// 身交易密码再次确认输入框
        bgView.addSubview(doubleDealTF)
        _ = doubleDealTF.sd_layout()
            .leftSpaceToView(doubleDealLab,tfTotitleLabWith)?
            .topSpaceToView(lineView,0)?
            .bottomSpaceToView(bgView,0)?
            .rightSpaceToView(eyeBtn2,5)
    }
    
  
    
    lazy var dealPswTF: UITextField = {
        let temp = UITextField()
        let placeholderStr = NSAttributedString(string:"请输入交易密码", attributes: [NSForegroundColorAttributeName : Normal_999Color.cgColor])
        //        temp.placeholder = "请输入真实姓名"
        temp.attributedPlaceholder = placeholderStr
        temp.font = Font_WL(14)
        temp.keyboardType = .numberPad
        temp.isSecureTextEntry = true
        temp.textColor = Normal_333Color
        temp.delegate = self
        return temp
    }()
    lazy var doubleDealTF: UITextField = {
        let temp = UITextField()
        let placeholderStr = NSAttributedString(string:"请再次输入交易密码", attributes: [NSForegroundColorAttributeName : Normal_999Color.cgColor])
        temp.attributedPlaceholder = placeholderStr
        temp.font = Font_WL(14)
        temp.keyboardType = .numberPad
        temp.isSecureTextEntry = true
        temp.textColor = Normal_333Color
        temp.delegate = self
        return temp
    }()
    
    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        
            return range.location < 6
        
        
    }
    
    
}
